<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCashbooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cashbooks', function (Blueprint $table) {
            $table->id()->startingValue(4321);
            $table->string('name', 10)->nullable('账本名');
            $table->unsignedBigInteger('user_id')->index()->comment('账本创建者');
            $table->timestamps();
        });

        Schema::create('user_cashbooks', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id')->index()->comment('用户ID');
            $table->unsignedBigInteger('cashbook_id')->index()->comment('账本ID');
            $table->unique(['user_id', 'cashbook_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cashbooks');
        Schema::dropIfExists('user_cashbooks');
    }
}
